Search in sources :

Example 6 with StudentException

use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.

the class StudentDaoImpl method getStudentList.

@Override
public List<Student> getStudentList() throws StudentException {
    List<Student> studentList = new ArrayList<>();
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Query query = session.createQuery("from Student");
        for (Object studentObj : query.list()) studentList.add((Student) studentObj);
        session.getTransaction().commit();
        session.close();
        return studentList;
    } catch (StudentDaoException e) {
        session.close();
        throw new StudentException(e.getMessage());
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) StudentDaoException(com.remswork.project.alice.dao.exception.StudentDaoException) Session(org.hibernate.Session)

Example 7 with StudentException

use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.

the class StudentServiceImpl method getStudentById.

@Override
public Student getStudentById(final long id) throws StudentException {
    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(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 : Student");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return null;
                    } else
                        throw new StudentException("Server Error");
                } catch (StudentException 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;
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) AsyncTask(android.os.AsyncTask) Gson(com.google.gson.Gson) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL)

Example 8 with StudentException

use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.

the class StudentServiceImpl method getStudentList.

@Override
public List<Student> getStudentList() throws StudentException {
    final List<Student> studentList = 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);
                    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++) {
                            studentList.add(gson.fromJson(jsonArray.get(ctr).toString(), Student.class));
                        }
                        return studentList;
                    } 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 : Student");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return studentList;
                    } else
                        throw new StudentException("Server Error");
                } catch (StudentException 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;
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) IOException(java.io.IOException) Student(com.remswork.project.alice.model.Student) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) StudentException(com.remswork.project.alice.exception.StudentException) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with StudentException

use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.

the class StudentServiceImpl method updateStudentById.

@Override
public Student updateStudentById(final long id, final Student newStudent, final long sectionId) throws StudentException {
    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(id)).concat("?sectionId=").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(newStudent));
                    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, Student.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 : Student");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return null;
                    } else
                        throw new StudentException("Server Error");
                } catch (StudentException 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;
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) AsyncTask(android.os.AsyncTask) Gson(com.google.gson.Gson) IOException(java.io.IOException) URL(java.net.URL) BufferedWriter(java.io.BufferedWriter) HttpURLConnection(java.net.HttpURLConnection) StudentException(com.remswork.project.alice.exception.StudentException) OutputStreamWriter(java.io.OutputStreamWriter) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with StudentException

use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.

the class UserService method updateSectionById.

public Student updateSectionById(final long id, final Student newstudent) throws SectionException {
    try {
        return new AsyncTask<Long, Student, Student>() {

            @Override
            protected Student doInBackground(Long... params) {
                try {
                    String link = "".concat(baseUri).concat("userDetail").concat("/").concat(params[0] + "");
                    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(newstudent));
                    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, Student.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);
                        return null;
                    } else
                        throw new StudentException("Server Error");
                } catch (StudentException e) {
                    e.printStackTrace();
                    return null;
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
        }.execute(id).get();
    } catch (InterruptedException e) {
        e.printStackTrace();
        return null;
    } catch (ExecutionException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) AsyncTask(android.os.AsyncTask) Gson(com.google.gson.Gson) IOException(java.io.IOException) URL(java.net.URL) BufferedWriter(java.io.BufferedWriter) HttpURLConnection(java.net.HttpURLConnection) StudentException(com.remswork.project.alice.exception.StudentException) OutputStreamWriter(java.io.OutputStreamWriter) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

StudentException (com.remswork.project.alice.exception.StudentException)27 Message (com.remswork.project.alice.model.support.Message)17 Student (com.remswork.project.alice.model.Student)15 Section (com.remswork.project.alice.model.Section)8 AsyncTask (android.os.AsyncTask)6 Gson (com.google.gson.Gson)6 StudentDaoException (com.remswork.project.alice.dao.exception.StudentDaoException)6 StudentServiceException (com.remswork.project.alice.web.service.exception.StudentServiceException)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 ExecutionException (java.util.concurrent.ExecutionException)6 Client (javax.ws.rs.client.Client)6 WebTarget (javax.ws.rs.client.WebTarget)6 Response (javax.ws.rs.core.Response)6 Session (org.hibernate.Session)6 SectionException (com.remswork.project.alice.exception.SectionException)5 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)5 SectionResourceLinks (com.remswork.project.alice.resource.links.SectionResourceLinks)5