Search in sources :

Example 41 with ClassException

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

the class GradeViewActivity method initRView.

public void initRView(final long classId) {
    final Handler handler = new Handler(getMainLooper());
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final ClassServiceImpl classService = new ClassServiceImpl();
                final List<Student> studenList = new ArrayList<>();
                final Set<Student> studentSet = classService.getStudentList(classId);
                for (Student student : studentSet) studenList.add(student);
                final StudentAdapter studentAdapter = new StudentAdapter(GradeViewActivity.this, studenList);
                final LinearLayoutManager layoutManager = new LinearLayoutManager(GradeViewActivity.this);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        recyclerView.setAdapter(studentAdapter);
                        recyclerView.setLayoutManager(layoutManager);
                        recyclerView.setItemAnimator(new DefaultItemAnimator());
                        if (studenList.size() < 1)
                            txtMsgContent.setVisibility(View.VISIBLE);
                    }
                });
            } catch (ClassException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : ArrayList(java.util.ArrayList) StudentAdapter(com.lieverandiver.thesisproject.adapter.StudentAdapter) Handler(android.os.Handler) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ClassServiceImpl(com.remswork.project.alice.service.impl.ClassServiceImpl)

Example 42 with ClassException

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

the class StudentViewActivity method initRView.

public void initRView(final long classId) {
    final Handler handler = new Handler(getMainLooper());
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final ClassServiceImpl classService = new ClassServiceImpl();
                final List<Student> studenList = new ArrayList<>();
                final Set<Student> studentSet = classService.getStudentList(classId);
                for (Student student : studentSet) studenList.add(student);
                Collections.sort(studenList, new Comparator<Student>() {

                    @Override
                    public int compare(final Student object1, final Student object2) {
                        return object1.getLastName().compareTo(object2.getLastName());
                    }
                });
                final StudentAdapter studentAdapter = new StudentAdapter(StudentViewActivity.this, studenList);
                final LinearLayoutManager layoutManager = new LinearLayoutManager(StudentViewActivity.this);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        recyclerView.setAdapter(studentAdapter);
                        recyclerView.setLayoutManager(layoutManager);
                        recyclerView.setItemAnimator(new DefaultItemAnimator());
                        if (studenList.size() < 1)
                            txtMsgContent.setVisibility(View.VISIBLE);
                    }
                });
            } catch (ClassException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : ArrayList(java.util.ArrayList) StudentAdapter(com.lieverandiver.thesisproject.adapter.StudentAdapter) Handler(android.os.Handler) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ClassServiceImpl(com.remswork.project.alice.service.impl.ClassServiceImpl)

Example 43 with ClassException

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

the class SliderClassFragment method init.

public void init() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                List<Class> classList = new ClassServiceImpl().getClassListByTeacherId(new TeacherHelper(getContext()).loadUser().get().getId());
                final ClassAdapter classAdapter = new ClassAdapter(getContext(), classList);
                final RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 2);
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        recyclerView.setAdapter(classAdapter);
                        recyclerView.setLayoutManager(layoutManager);
                        recyclerView.setItemAnimator(new DefaultItemAnimator());
                        progressBar.setVisibility(View.INVISIBLE);
                    }
                });
            } catch (ClassException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : ClassAdapter(com.lieverandiver.thesisproject.adapter.ClassAdapter) ClassException(com.remswork.project.alice.exception.ClassException) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ClassServiceImpl(com.remswork.project.alice.service.impl.ClassServiceImpl) Class(com.remswork.project.alice.model.Class) RecyclerView(android.support.v7.widget.RecyclerView) TeacherHelper(com.lieverandiver.thesisproject.helper.TeacherHelper)

Example 44 with ClassException

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

the class ClassServiceImpl method addStudentById.

@Deprecated
@Override
public Student addStudentById(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("?scheduleId=").concat(String.valueOf(id));
                    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, 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 : 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;
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) AsyncTask(android.os.AsyncTask) Gson(com.google.gson.Gson) ClassException(com.remswork.project.alice.exception.ClassException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL)

Example 45 with ClassException

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

the class ClassServiceImpl method deleteStudentById.

@Deprecated
@Override
public Student deleteStudentById(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("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, 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 : 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;
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) AsyncTask(android.os.AsyncTask) Gson(com.google.gson.Gson) ClassException(com.remswork.project.alice.exception.ClassException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL)

Aggregations

ClassException (com.remswork.project.alice.exception.ClassException)55 Message (com.remswork.project.alice.model.support.Message)46 Class (com.remswork.project.alice.model.Class)18 AsyncTask (android.os.AsyncTask)17 Gson (com.google.gson.Gson)17 IOException (java.io.IOException)17 InputStream (java.io.InputStream)17 HttpURLConnection (java.net.HttpURLConnection)17 URL (java.net.URL)17 ExecutionException (java.util.concurrent.ExecutionException)17 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)16 Client (javax.ws.rs.client.Client)16 WebTarget (javax.ws.rs.client.WebTarget)16 Response (javax.ws.rs.core.Response)16 Student (com.remswork.project.alice.model.Student)14 Schedule (com.remswork.project.alice.model.Schedule)13 ArrayList (java.util.ArrayList)9 ClientBuilder (javax.ws.rs.client.ClientBuilder)7 Builder (javax.ws.rs.client.Invocation.Builder)7 JSONArray (org.json.JSONArray)7