use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassStudentListResource method deleteStudentById.
@DELETE
@Path("{studentId}")
public Response deleteStudentById(@PathParam("classId") long classId, @PathParam("studentId") long id) {
try {
ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
Student student = classService.deleteStudentById(classId, id);
student.addLink(resourceLinks.self(classId, id));
return Response.status(Response.Status.OK).entity(student).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 ClassServiceImpl method getStudentListOrdered.
@Deprecated
public List<Student> getStudentListOrdered(final long classId) throws ClassException {
final List<Student> studentSet = new ArrayList<>();
try {
return new AsyncTask<String, List<Student>, List<Student>>() {
@Override
protected List<Student> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(classId)).concat("/").concat("student");
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++) {
studentSet.add(gson.fromJson(jsonArray.get(ctr).toString(), Student.class));
}
Collections.sort(studentSet, new Comparator<Student>() {
@Override
public int compare(final Student object1, final Student object2) {
return object1.getLastName().compareTo(object2.getLastName());
}
});
return studentSet;
} 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);
Collections.sort(studentSet, new Comparator<Student>() {
@Override
public int compare(final Student object1, final Student object2) {
return object1.getLastName().compareTo(object2.getLastName());
}
});
return studentSet;
} 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 getStudentList.
@Deprecated
@Override
public Set<Student> getStudentList(final long classId) throws ClassException {
final Set<Student> studentSet = new HashSet<>();
try {
return new AsyncTask<String, Set<Student>, Set<Student>>() {
@Override
protected Set<Student> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(classId)).concat("/").concat("student");
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++) {
studentSet.add(gson.fromJson(jsonArray.get(ctr).toString(), Student.class));
}
return studentSet;
} 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 studentSet;
} 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 updateClassById.
@Override
public Class updateClassById(final long id, final Class newClass, final long teacherId, final long subjectId, final long sectionId) throws ClassException {
try {
return new AsyncTask<String, Class, Class>() {
@Override
protected Class doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(id)).concat("?teacherId=").concat(String.valueOf(teacherId)).concat("&subjectId=").concat(String.valueOf(subjectId)).concat("§ionId=").concat(String.valueOf(sectionId));
Gson gson = new Gson();
URL url = new URL(link);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("PUT");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream os = httpURLConnection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(gson.toJson(newClass));
writer.flush();
writer.close();
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, Class.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 deleteScheduleById.
@Override
public Schedule deleteScheduleById(final long classId, final long id) 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("/").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 : 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;
}
}
Aggregations