Search in sources :

Example 21 with Teacher

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

the class ActivityChangePassword method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_changepassword);
    text1 = findViewById(R.id.activity_changepassword_text1);
    text2 = findViewById(R.id.activity_changepassword_text2);
    button = findViewById(R.id.activityt_changepassword_button);
    btnCancel = findViewById(R.id.activityt_changepassword_button_cancel);
    progressBar = findViewById(R.id.progressbar_cp);
    button.setOnClickListener(this);
    btnCancel.setOnClickListener(this);
    retrofit = new DI().getRetrofit();
    userService = retrofit.create(UserService.class);
    teacherService = new TeacherServiceImpl();
    progressBar.setVisibility(View.INVISIBLE);
    try {
        teacher = teacherService.getTeacherById(getIntent().getExtras().getLong("teacherId"));
    } catch (Exception e) {
        e.printStackTrace();
        teacher = new Teacher();
    }
}
Also used : DI(io.classify.DI) UserService(io.classify.service.UserService) Teacher(com.remswork.project.alice.model.Teacher) TeacherServiceImpl(com.remswork.project.alice.service.impl.TeacherServiceImpl)

Example 22 with Teacher

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

the class TeacherServiceImpl method addTeacher.

@Deprecated
@Override
public Teacher addTeacher(final Teacher teacher, final long departmentId) throws TeacherException {
    try {
        return new AsyncTask<Teacher, Teacher, Teacher>() {

            @Override
            protected Teacher doInBackground(Teacher... params) {
                try {
                    Gson gson = new Gson();
                    URL url = new URL(baseUri);
                    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                    httpURLConnection.setRequestMethod("POST");
                    httpURLConnection.setRequestProperty("Content-Type", "application/json");
                    httpURLConnection.setDoOutput(true);
                    Uri.Builder builder = new Uri.Builder().appendQueryParameter("departmentId", String.valueOf(departmentId));
                    String query = builder.build().getEncodedQuery();
                    OutputStreamWriter writer = new OutputStreamWriter(httpURLConnection.getOutputStream());
                    writer.write(query);
                    writer.write(gson.toJson(teacher).toString());
                    writer.flush();
                    writer.close();
                    httpURLConnection.connect();
                    if (httpURLConnection.getResponseCode() == 201) {
                        InputStream inputStream = httpURLConnection.getInputStream();
                        String stringData = "";
                        int data;
                        while ((data = inputStream.read()) != -1) {
                            stringData += (char) data;
                        }
                        return gson.fromJson(stringData, Teacher.class);
                    } else if (httpURLConnection.getResponseCode() == 400) {
                        InputStream inputStream = httpURLConnection.getInputStream();
                        String stringData = "";
                        int data;
                        while ((data = inputStream.read()) != -1) {
                            stringData += (char) data;
                        }
                        Message message = gson.fromJson(stringData, Message.class);
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return null;
                    } else
                        throw new TeacherException("Server Error");
                } catch (TeacherException e) {
                    e.printStackTrace();
                    return null;
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
        }.execute(teacher).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) AsyncTask(android.os.AsyncTask) Teacher(com.remswork.project.alice.model.Teacher) Gson(com.google.gson.Gson) IOException(java.io.IOException) Uri(android.net.Uri) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) TeacherException(com.remswork.project.alice.exception.TeacherException) OutputStreamWriter(java.io.OutputStreamWriter) ExecutionException(java.util.concurrent.ExecutionException)

Example 23 with Teacher

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

the class TeacherServiceImpl method addTeacher.

@Deprecated
@Override
public Teacher addTeacher(final Teacher teacher) throws TeacherException {
    try {
        if (teacher.getDepartment() != null) {
            teacher.getDepartment().setId(0);
        }
        return (Teacher) new AsyncTask<Teacher, Teacher, Teacher>() {

            @Override
            protected Teacher doInBackground(Teacher... params) {
                try {
                    Gson gson = new Gson();
                    URL url = new URL(baseUri);
                    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                    httpURLConnection.setRequestMethod("POST");
                    httpURLConnection.setRequestProperty("Content-Type", "application/json");
                    httpURLConnection.setDoOutput(true);
                    OutputStreamWriter writer = new OutputStreamWriter(httpURLConnection.getOutputStream());
                    writer.write(gson.toJson(teacher).toString());
                    writer.flush();
                    writer.close();
                    httpURLConnection.connect();
                    if (httpURLConnection.getResponseCode() == 201) {
                        InputStream inputStream = httpURLConnection.getInputStream();
                        String stringData = "";
                        int data;
                        while ((data = inputStream.read()) != -1) {
                            stringData += (char) data;
                        }
                        return gson.fromJson(stringData, Teacher.class);
                    } else if (httpURLConnection.getResponseCode() == 400) {
                        InputStream inputStream = httpURLConnection.getInputStream();
                        String stringData = "";
                        int data;
                        while ((data = inputStream.read()) != -1) {
                            stringData += (char) data;
                        }
                        Message message = gson.fromJson(stringData, Message.class);
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return null;
                    } else
                        throw new TeacherException("Server Error");
                } catch (TeacherException e) {
                    e.printStackTrace();
                    return null;
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
        }.execute(teacher).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) Teacher(com.remswork.project.alice.model.Teacher) Gson(com.google.gson.Gson) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) TeacherException(com.remswork.project.alice.exception.TeacherException) OutputStreamWriter(java.io.OutputStreamWriter) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with Teacher

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

the class DepartmentDaoImpl method deleteDepartmentById.

@Override
public Department deleteDepartmentById(long id) throws DepartmentException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Department department = session.get(Department.class, id);
        if (department == null)
            throw new DepartmentDaoException("Department with id : " + id + " does not exist.");
        // to avoid the constraints restriction we meed to remove department from the teacher
        // that having the department
        Query teacherQuery = session.createQuery("from Teacher");
        for (Object teacherObj : teacherQuery.list()) {
            Teacher teacher = (Teacher) teacherObj;
            if (teacher.getDepartment() == null)
                continue;
            if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
                teacher.setDepartment(null);
            }
        }
        // to avoid the constraints restriction we meed to delete the section that having the department
        Query sectionQuery = session.createQuery("from Section");
        for (Object sectionObj : sectionQuery.list()) {
            Section section = (Section) sectionObj;
            if (section.getDepartment() == null)
                continue;
            if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
                session.delete(section);
            }
        }
        // to avoid the constraints restriction we meed to remove department from the class's teacher and section
        // that having the department
        Query classQuery = session.createQuery("from Class");
        for (Object classObj : classQuery.list()) {
            Class _class = (Class) classObj;
            Teacher teacher = _class.getTeacher();
            Section section = _class.getSection();
            if (teacher != null) {
                if (teacher.getDepartment() != null) {
                    if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
                        teacher.setDepartment(null);
                    }
                }
            }
            if (section != null) {
                if (section.getDepartment() != null) {
                    if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
                        _class.setSection(null);
                    }
                }
            }
        }
        session.delete(department);
        session.getTransaction().commit();
        session.close();
        return department;
    } catch (DepartmentDaoException e) {
        session.close();
        throw new DepartmentException(e.getMessage());
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Query(org.hibernate.Query) DepartmentException(com.remswork.project.alice.exception.DepartmentException) Teacher(com.remswork.project.alice.model.Teacher) Class(com.remswork.project.alice.model.Class) DepartmentDaoException(com.remswork.project.alice.dao.exception.DepartmentDaoException) Section(com.remswork.project.alice.model.Section) Session(org.hibernate.Session)

Example 25 with Teacher

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

the class FormulaDaoImpl method updateFormulaById.

@Override
public Formula updateFormulaById(long id, Formula newFormula, long subjectId, long teacherId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Formula formula = session.get(Formula.class, id);
        Subject subject = session.get(Subject.class, subjectId);
        Teacher teacher = session.get(Teacher.class, teacherId);
        Term term = session.get(Term.class, termId);
        if (newFormula == null)
            newFormula = new Formula();
        if (formula == null)
            throw new GradingFactorDaoException("Formula with id : " + id + " does not exist");
        if (subject == null && subjectId != 0)
            throw new GradingFactorDaoException("Factor's subject with id : " + subjectId + " does not exist");
        if (teacher == null && teacherId != 0)
            throw new GradingFactorDaoException("Factor's teacher with id : " + teacherId + " does not exist");
        if (term == null && termId != 0)
            throw new GradingFactorDaoException("Factor's term with id : " + termId + " does not exist");
        formula.setActivityPercentage(newFormula.getActivityPercentage());
        formula.setAssignmentPercentage(newFormula.getAssignmentPercentage());
        formula.setAttendancePercentage(newFormula.getAttendancePercentage());
        formula.setExamPercentage(newFormula.getExamPercentage());
        formula.setProjectPercentage(newFormula.getProjectPercentage());
        formula.setQuizPercentage(newFormula.getQuizPercentage());
        formula.setRecitationPercentage(newFormula.getRecitationPercentage());
        if (subjectId > 0) {
            if (subjectId == (formula.getSubject() != null ? formula.getSubject().getId() : 0))
                throw new GradingFactorException("Formula's  subject with id : " + subjectId + " already exist");
            formula.setSubject(subject);
        }
        if (teacherId > 0) {
            if (teacherId == (formula.getTeacher() != null ? formula.getTeacher().getId() : 0))
                throw new GradingFactorException("Formula's  teacher with id : " + teacherId + " already exist");
            formula.setTeacher(teacher);
        }
        if (termId > 0) {
            if (termId == (formula.getTerm() != null ? formula.getTerm().getId() : 0))
                throw new GradingFactorException("Formula's  term with id : " + termId + " already exist");
            formula.setTerm(term);
        }
        session.getTransaction().commit();
        session.close();
        return formula;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Formula(com.remswork.project.alice.model.Formula) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Teacher(com.remswork.project.alice.model.Teacher) Term(com.remswork.project.alice.model.Term) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Subject(com.remswork.project.alice.model.Subject) Session(org.hibernate.Session)

Aggregations

Teacher (com.remswork.project.alice.model.Teacher)29 TeacherException (com.remswork.project.alice.exception.TeacherException)14 Message (com.remswork.project.alice.model.support.Message)14 TeacherServiceException (com.remswork.project.alice.web.service.exception.TeacherServiceException)6 Client (javax.ws.rs.client.Client)6 WebTarget (javax.ws.rs.client.WebTarget)6 Response (javax.ws.rs.core.Response)6 Subject (com.remswork.project.alice.model.Subject)5 Gson (com.google.gson.Gson)4 TeacherHelper (com.lieverandiver.thesisproject.helper.TeacherHelper)4 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)4 Department (com.remswork.project.alice.model.Department)4 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)4 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ExecutionException (java.util.concurrent.ExecutionException)4 ClientBuilder (javax.ws.rs.client.ClientBuilder)4