use of com.remswork.project.alice.exception.ClassException 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.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method addScheduleById.
@Override
public Schedule addScheduleById(final long classId, final long scheduleId) throws ClassException {
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(classId)).concat("/").concat("schedule").concat("?scheduleId=").concat(String.valueOf(scheduleId));
Gson gson = new Gson();
URL url = new URL(link);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200 || httpURLConnection.getResponseCode() == 201) {
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 : Class");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return null;
} else
throw new ClassException("Server Error");
} catch (ClassException 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;
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method getStudentById.
@Deprecated
@Override
public Student getStudentById(final long classId, final long id) throws ClassException {
try {
return new AsyncTask<String, Student, Student>() {
@Override
protected Student doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(classId)).concat("/").concat("student").concat("/").concat(String.valueOf(id));
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;
}
return gson.fromJson(jsonData, Student.class);
} 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 null;
} else
throw new ClassException("Server Error");
} catch (ClassException 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;
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassResource method deleteClassById.
@DELETE
@Path("{classId}")
public Response deleteClassById(@PathParam("classId") long id) {
try {
ClassResourceLinks resourceLinks = new ClassResourceLinks(uriInfo);
TeacherResourceLinks teacherResourceLinks = new TeacherResourceLinks(uriInfo);
SubjectResourceLinks subjectResourceLinks = new SubjectResourceLinks(uriInfo);
SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
Class _class = classService.deleteClassById(id);
_class.addLink(resourceLinks.self(id));
_class.addLink(resourceLinks.schedule(id));
_class.addLink(resourceLinks.student(id));
if (_class.getTeacher() != null)
_class.getTeacher().addLink(teacherResourceLinks.self(_class.getTeacher().getId()));
if (_class.getSubject() != null)
_class.getSubject().addLink(subjectResourceLinks.self(_class.getSubject().getId()));
if (_class.getSection() != null)
_class.getSection().addLink(sectionResourceLinks.self(_class.getSection().getId()));
return Response.status(Response.Status.OK).entity(_class).build();
} catch (ClassException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassStudentListResource method addStudentById.
@POST
public Response addStudentById(@PathParam("classId") long classId) {
try {
ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
if (studentId == 0)
throw new ClassDaoException("Query param : studentId is required");
Student student = classService.addStudentById(classId, studentId);
student.addLink(resourceLinks.self(classId, studentId));
return Response.status(Response.Status.OK).entity(student).build();
} catch (ClassException | ClassDaoException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
Aggregations