Search in sources :

Example 21 with Class

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

the class ActivityDaoImpl method updateActivityById.

@Override
public Activity updateActivityById(long id, Activity newActivity, long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Activity activity = session.get(Activity.class, id);
        Class _class = session.get(Class.class, classId);
        Term term = session.get(Term.class, termId);
        if (newActivity == null)
            newActivity = new Activity();
        if (activity == null)
            throw new GradingFactorDaoException("Activity with id : " + id + " does not exist");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Activity's class with id : " + classId + " does not exist");
        if (term == null && termId > 0)
            throw new GradingFactorDaoException("Activity's term with id : " + termId + " does not exist");
        if (!(newActivity.getTitle() != null ? newActivity.getTitle() : "").trim().isEmpty())
            activity.setTitle(newActivity.getTitle());
        if (!(newActivity.getDate() != null ? newActivity.getDate() : "").trim().isEmpty())
            activity.setDate(newActivity.getDate());
        if (classId > 0) {
            if (classId == (activity.get_class() != null ? activity.get_class().getId() : 0))
                throw new GradingFactorDaoException("Activity's  class with id : " + classId + " already exist");
            activity.set_class(_class);
        }
        if (termId > 0) {
            if (termId != (activity.getTerm() != null ? activity.getTerm().getId() : 0))
                activity.setTerm(term);
        }
        session.getTransaction().commit();
        session.close();
        return activity;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Class(com.remswork.project.alice.model.Class) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 22 with Class

use of com.remswork.project.alice.model.Class 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 23 with Class

use of com.remswork.project.alice.model.Class 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 24 with Class

use of com.remswork.project.alice.model.Class 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 25 with Class

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

the class GradeResultActivity2 method load.

public void load() {
    try {
        final FormulaService formulaService = new FormulaServiceImpl();
        final GradeService gradeService = new GradeServiceImpl();
        final long termId = getIntent().getExtras().getLong("termId");
        final long classId = getIntent().getExtras().getLong("classId");
        final Class _class = classService.getClassById(classId);
        final long subjectId = _class.getSubject() != null ? _class.getSubject().getId() : 0;
        final long teacherId = _class.getTeacher() != null ? _class.getTeacher().getId() : 0;
        final Formula formula = formulaService.getFormulaBySubjectAndTeacherId(subjectId, teacherId, termId);
        Log.i("SOMETHINGGG", "CLASSID" + classId + " FORMULAID" + formula.getId());
        final io.classify.service.GradeService gr = new DI().getRetrofit().create(io.classify.service.GradeService.class);
        for (final Student student : classService.getStudentListOrdered(classId)) {
            Log.i("TATATE", String.format("test/total/class/{%d}/term/{%d}/teacher/{%d}/subject/{%d}/student/{%d}", classId, termId, teacherId, subjectId, student.getId()));
            gr.findAll(classId, teacherId, subjectId, student.getId()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<MarkDto>() {

                @Override
                public void accept(MarkDto result) throws Exception {
                    if (!result.getMidterm().equals("NaN")) {
                        Grade grade = new Grade();
                        grade.setStudent(student);
                        grade.setTotalScore(Double.parseDouble(result.getMidterm()));
                        Grade grade2 = new Grade();
                        grade2.setStudent(student);
                        grade2.setTotalScore(Double.parseDouble(result.getFinalterm()));
                        Mark mark = new Mark();
                        mark.setMidterm(grade);
                        mark.setFinalterm(grade2);
                        gradeList.add(mark);
                        notifyChange();
                    }
                }
            }, new Consumer<Throwable>() {

                @Override
                public void accept(Throwable throwable) throws Exception {
                    Log.i("TAETAE", throwable.toString());
                }
            });
        // final Student cStudent = student;
        // Log.i("SOMETHINGGG", "Student" + student.getId());
        // Log.i("FORMULA",formula.getId()+ "");
        // new Thread(new Runnable() {
        // @Override
        // public void run() {
        // try {
        // long studentId = cStudent.getId();
        // List<Grade> temp = gradeService.getGradeListByClass(classId, studentId, termId);
        // Grade grade = temp.size() > 0 ? temp.get(0) : new Grade();
        // 
        // Log.i("GRADE",grade.getId()+ "");
        // 
        // double actScore = ((double) formula.getActivityPercentage() / 100) * grade.getActivityScore();
        // double assScore = ((double) formula.getAssignmentPercentage() / 100) * grade.getAssignmentScore();
        // double attScore = ((double) formula.getAttendancePercentage() / 100) * grade.getAttendanceScore();
        // double exaScore = ((double) formula.getExamPercentage() / 100) * grade.getExamScore();
        // double proScore = ((double) formula.getProjectPercentage() / 100) * grade.getProjectScore();
        // double quiScore = ((double) formula.getQuizPercentage() / 100) * grade.getQuizScore();
        // 
        // grade.setTotalScore(
        // actScore + assScore + attScore + exaScore + proScore + quiScore
        // );
        // 
        // grade.setStudent(student);
        // 
        // Log.i("SOMETHINGGG", "actScore" + formula.getActivityPercentage());
        // Log.i("SOMETHINGGG", "assScore" + formula.getAssignmentPercentage());
        // Log.i("SOMETHINGGG", "attScore" + formula.getAttendancePercentage());
        // Log.i("SOMETHINGGG", "exaScore" + formula.getExamPercentage());
        // Log.i("SOMETHINGGG", "proScore" + formula.getProjectPercentage());
        // Log.i("SOMETHINGGG", "quiScore" + formula.getQuizPercentage());
        // Log.i("SOMETHINGGG", "Student" + studentId);
        // Log.i("SOMETHINGGG", "Grade" + grade.getId());
        // 
        // gradeList.add(grade);
        // notifyChange();
        // } catch (Exception e) {
        // e.printStackTrace();
        // }
        // }
        // }).start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : GradeService(com.remswork.project.alice.service.GradeService) FormulaService(com.remswork.project.alice.service.FormulaService) DI(io.classify.DI) Mark(io.classify.model.Mark) Grade(com.remswork.project.alice.model.Grade) Student(com.remswork.project.alice.model.Student) MarkDto(io.classify.model.MarkDto) Formula(com.remswork.project.alice.model.Formula) GradeServiceImpl(com.remswork.project.alice.service.impl.GradeServiceImpl) Class(com.remswork.project.alice.model.Class) FormulaServiceImpl(com.remswork.project.alice.service.impl.FormulaServiceImpl)

Aggregations

Class (com.remswork.project.alice.model.Class)59 Session (org.hibernate.Session)35 ClassException (com.remswork.project.alice.exception.ClassException)18 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)16 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)16 Message (com.remswork.project.alice.model.support.Message)16 ClassDaoException (com.remswork.project.alice.dao.exception.ClassDaoException)15 Query (org.hibernate.Query)10 Student (com.remswork.project.alice.model.Student)9 ArrayList (java.util.ArrayList)9 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)8 Client (javax.ws.rs.client.Client)8 WebTarget (javax.ws.rs.client.WebTarget)8 Response (javax.ws.rs.core.Response)8 Grade (com.remswork.project.alice.model.Grade)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