Search in sources :

Example 21 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeDaoImpl method getGradeListByStudentId.

@Override
public List<Grade> getGradeListByStudentId(long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Grade> gradeList = new ArrayList<>();
        String hql = "from Grade as G where G.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        for (Object object : query.list()) gradeList.add((Grade) object);
        session.getTransaction().commit();
        session.close();
        return gradeList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 22 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeDaoImpl method getGradeById.

@Override
public Grade getGradeById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Grade grade = session.get(Grade.class, id);
        if (grade == null)
            throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
        session.getTransaction().commit();
        session.close();
        return grade;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 23 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeServiceImpl method getGradeListByClass.

@Override
public List<Grade> getGradeListByClass(final long classId, final long studentId, final long termId) throws GradingFactorException {
    final List<Grade> gradeList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Grade>, List<Grade>>() {

            @Override
            protected List<Grade> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?classId=").concat(String.valueOf(classId)).concat("&studentId=").concat(String.valueOf(studentId)).concat("&termId=").concat(String.valueOf(termId));
                    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++) {
                            gradeList.add(gson.fromJson(jsonArray.get(ctr).toString(), Grade.class));
                        }
                        return gradeList;
                    } 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 : Grade");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return gradeList;
                    } else
                        throw new GradingFactorException("Server Error");
                } catch (GradingFactorException 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) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) Grade(com.remswork.project.alice.model.Grade) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeServiceImpl method getGradeListByStudentId.

@Override
public List<Grade> getGradeListByStudentId(final long studenId) throws GradingFactorException {
    final List<Grade> gradeList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Grade>, List<Grade>>() {

            @Override
            protected List<Grade> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?studentId=").concat(String.valueOf(studenId));
                    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++) {
                            gradeList.add(gson.fromJson(jsonArray.get(ctr).toString(), Grade.class));
                        }
                        return gradeList;
                    } 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 : Grade");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return gradeList;
                    } else
                        throw new GradingFactorException("Server Error");
                } catch (GradingFactorException 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) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) Grade(com.remswork.project.alice.model.Grade) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 25 with Grade

use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.

the class GradeResource method getGradeList.

@GET
public Response getGradeList() {
    try {
        List<Grade> gradeList;
        if (classId != 0 && studentId != 0 && termId != 0)
            gradeList = gradeService.getGradeListByClass(classId, studentId, termId);
        else if (classId != 0 && studentId != 0)
            gradeList = gradeService.getGradeListByClass(classId, studentId);
        else if (studentId != 0 && termId != 0)
            gradeList = gradeService.getGradeListByStudentId(studentId, termId);
        else if (studentId != 0)
            gradeList = gradeService.getGradeListByStudentId(studentId);
        else
            gradeList = gradeService.getGradeList();
        GenericEntity<List<Grade>> entity = new GenericEntity<List<Grade>>(gradeList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (GradingFactorException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Grade(com.remswork.project.alice.model.Grade) List(java.util.List)

Aggregations

Grade (com.remswork.project.alice.model.Grade)32 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)25 Student (com.remswork.project.alice.model.Student)20 ArrayList (java.util.ArrayList)17 CardView (android.support.v7.widget.CardView)13 RecyclerView (android.support.v7.widget.RecyclerView)13 View (android.view.View)13 Button (android.widget.Button)13 TextView (android.widget.TextView)13 List (java.util.List)12 CompoundButton (android.widget.CompoundButton)11 ToggleButton (android.widget.ToggleButton)11 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)7 Class (com.remswork.project.alice.model.Class)7 Session (org.hibernate.Session)7 Formula (com.remswork.project.alice.model.Formula)6 FormulaService (com.remswork.project.alice.service.FormulaService)6 GradeService (com.remswork.project.alice.service.GradeService)6 FormulaServiceImpl (com.remswork.project.alice.service.impl.FormulaServiceImpl)6 GradeServiceImpl (com.remswork.project.alice.service.impl.GradeServiceImpl)6