Search in sources :

Example 16 with ClassException

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

the class ClassServiceImpl method getClassList.

@Override
public List<Class> getClassList() throws ClassException {
    final List<Class> _classList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Class>, List<Class>>() {

            @Override
            protected List<Class> 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++) {
                            _classList.add(gson.fromJson(jsonArray.get(ctr).toString(), Class.class));
                        }
                        return _classList;
                    } 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 _classList;
                    } 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;
    }
}
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) ClassException(com.remswork.project.alice.exception.ClassException) JSONException(org.json.JSONException) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Class(com.remswork.project.alice.model.Class) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with ClassException

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

the class ClassServiceImpl method getClassListByTeacherId.

@Override
public List<Class> getClassListByTeacherId(final long teacherId) throws ClassException {
    final List<Class> _classList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Class>, List<Class>>() {

            @Override
            protected List<Class> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?teacherId=").concat(String.valueOf(teacherId));
                    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++) {
                            _classList.add(gson.fromJson(jsonArray.get(ctr).toString(), Class.class));
                        }
                        return _classList;
                    } 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 _classList;
                    } 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;
    }
}
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) ClassException(com.remswork.project.alice.exception.ClassException) JSONException(org.json.JSONException) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Class(com.remswork.project.alice.model.Class) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with ClassException

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

the class ClassServiceImpl method getClassListByStudentId.

@Override
public List<Class> getClassListByStudentId(final long studentId) throws ClassException {
    final List<Class> _classList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Class>, List<Class>>() {

            @Override
            protected List<Class> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?studentId=").concat(String.valueOf(studentId));
                    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++) {
                            _classList.add(gson.fromJson(jsonArray.get(ctr).toString(), Class.class));
                        }
                        return _classList;
                    } 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 _classList;
                    } 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;
    }
}
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) ClassException(com.remswork.project.alice.exception.ClassException) JSONException(org.json.JSONException) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Class(com.remswork.project.alice.model.Class) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with ClassException

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

the class ScheduleViewActivity 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<Schedule> scheduleList = new ArrayList<>();
                final Set<Schedule> scheduleSet = classService.getScheduleList(classId);
                for (Schedule schedule : scheduleSet) scheduleList.add(schedule);
                final ScheduleAdapter scheduleAdapter = new ScheduleAdapter(ScheduleViewActivity.this, scheduleList);
                final LinearLayoutManager layoutManager = new LinearLayoutManager(ScheduleViewActivity.this);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                handler.post(new Runnable() {

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

Example 20 with ClassException

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

the class Home_Schedule_Slidebar_Fragment method init.

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

        @Override
        public void run() {
            try {
                final List<Schedule> scheduleList = new ArrayList<>();
                TeacherHelper teacherHelper = new TeacherHelper(getContext());
                ClassServiceImpl classService = new ClassServiceImpl();
                Class _class = null;
                for (Class c : classService.getClassList()) {
                    if (c.getTeacher() == null)
                        continue;
                    if (c.getTeacher().getId() == teacherHelper.loadUser().get().getId()) {
                        _class = c;
                        Log.i("myTAG", "id : " + c.getId());
                        break;
                    }
                }
                // test
                _class = classService.getClassById(40);
                if (_class != null) {
                    for (Schedule schedule : classService.getScheduleList(_class.getId())) scheduleList.add(schedule);
                }
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        scheduleRecyclerView = (RecyclerView) customView.findViewById(R.id.shedule_recyclerview);
                        ScheduleAdapter scheduleAdapter = new ScheduleAdapter(getContext(), scheduleList);
                        scheduleRecyclerView.setAdapter(scheduleAdapter);
                        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
                        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                        scheduleRecyclerView.setLayoutManager(layoutManager);
                        scheduleRecyclerView.setItemAnimator(new DefaultItemAnimator());
                    }
                });
            } catch (ClassException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : ScheduleAdapter(com.lieverandiver.thesisproject.ScheduleAdapter) ArrayList(java.util.ArrayList) ClassException(com.remswork.project.alice.exception.ClassException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Schedule(com.remswork.project.alice.model.Schedule) 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)

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