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();
}
}
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;
}
}
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;
}
}
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());
}
}
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());
}
}
Aggregations