use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.
the class GradeDaoImpl method getGradeList.
@Override
public List<Grade> getGradeList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Grade> gradeList = new ArrayList<>();
Query query = session.createQuery("from Grade");
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());
}
}
use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.
the class GradeDaoImpl method deleteGradeById.
@Override
public Grade deleteGradeById(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.delete(grade);
session.getTransaction().commit();
session.close();
return grade;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.
the class ProjectInputActivityF method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_z_input_project);
init();
buttonSubmit.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
final long classId = getIntent().getExtras().getLong("classId");
try {
Project project = new Project();
project.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Project");
project.setDate(textViewDate.getText().toString());
if (editTextTotal.getText().toString().equals("")) {
toggleButtonhideandshow.setChecked(false);
getDialogEmptyTotal.setVisibility(View.VISIBLE);
recyclerViewStudentInput.setVisibility(View.GONE);
return;
} else {
project.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
}
studentAdapter.setTotalItem(project.getItemTotal());
studentAdapter.onValidate(true);
if (studentAdapter.isNoError()) {
project = projectService.addProject(project, classId, 1L);
for (int i = 0; i < studentList.size(); i++) {
// Student id
final long studentId = studentList.get(i).getId();
//
int score = studentAdapter.getScore(i);
Student student = studentList.get(i);
projectService.addProjectResult(score, project.getId(), student.getId());
// Adding Grade for project
new Thread(new Runnable() {
@Override
public void run() {
try {
final List<Project> projectList = projectService.getProjectListByClassId(classId);
final double[] fProject = new double[projectList.size()];
final long sId = studentId;
double tempTotal = 0;
try {
List<Grade> tempList = gradeService.getGradeListByClass(classId, sId, 2L);
grade = (tempList.size() > 0 ? tempList.get(0) : null);
} catch (GradingFactorException e) {
e.printStackTrace();
grade = null;
}
if (grade == null) {
Grade _grade = new Grade();
grade = gradeService.addGrade(_grade, classId, studentId, 2L);
}
final Grade lGrade = grade;
final long gradeId = grade.getId();
for (int i = 0; i < fProject.length; i++) {
final double total = projectList.get(i).getItemTotal();
final double score = projectService.getProjectResultByProjectAndStudentId(projectList.get(i).getId(), sId).getScore();
fProject[i] = (score / total) * 100;
}
for (int i = 0; i < fProject.length; i++) tempTotal += fProject[i];
// after looping
if (fProject.length > 0)
tempTotal /= fProject.length;
else
tempTotal = 0;
lGrade.setActivityScore(tempTotal);
lGrade.setTotalScore(lGrade.getTotalScore() + tempTotal);
gradeService.updateGradeById(gradeId, lGrade);
} catch (GradingFactorException e) {
e.printStackTrace();
}
}
}).start();
}
dialogSucces.setVisibility(View.VISIBLE);
Toast.makeText(ProjectInputActivityF.this, "Success", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ProjectInputActivityF.this, "Failed", Toast.LENGTH_LONG).show();
dialogFailed.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.
the class GradeDaoImpl method updateGrade.
@Override
public Grade updateGrade(long id, Grade newGrade, long classId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Grade grade = session.get(Grade.class, id);
Class _class = session.get(Class.class, classId);
Student student = session.get(Student.class, studentId);
if (newGrade == null)
newGrade = new Grade();
if (grade == null)
throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
if (student == null && studentId != 0)
throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
if (classId < 0)
throw new GradingFactorDaoException("The class id is invalid");
if (studentId < 0)
throw new GradingFactorDaoException("The student id is invalid");
if (newGrade.getTotalScore() >= 0 && grade.getTotalScore() > 0)
grade.setTotalScore(newGrade.getTotalScore());
if (newGrade.getActivityScore() > 0 && grade.getActivityScore() > 0)
grade.setActivityScore(newGrade.getActivityScore());
if (newGrade.getAssignmentScore() > 0 && grade.getAssignmentScore() > 0)
grade.setAssignmentScore(newGrade.getAssignmentScore());
if (newGrade.getAttendanceScore() > 0 && grade.getAttendanceScore() > 0)
grade.setAttendanceScore(newGrade.getAttendanceScore());
if (newGrade.getExamScore() > 0 && grade.getExamScore() > 0)
grade.setExamScore(newGrade.getExamScore());
if (newGrade.getProjectScore() > 0 && grade.getProjectScore() > 0)
grade.setProjectScore(newGrade.getProjectScore());
if (newGrade.getQuizScore() > 0 && grade.getQuizScore() > 0)
grade.setQuizScore(newGrade.getQuizScore());
if (classId > 0) {
if ((grade.get_class() != null ? grade.get_class().getId() : 0) == classId)
throw new GradingFactorDaoException("The class id is already exist");
grade.set_class(_class);
}
if (studentId > 0) {
if ((grade.getStudent() != null ? grade.getStudent().getId() : 0) == studentId)
throw new GradingFactorDaoException("The student id is already exist");
grade.setStudent(student);
}
grade.set_class(_class);
grade.setStudent(student);
session.getTransaction().commit();
session.close();
return grade;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.
the class GradeDaoImpl method getGradeListByClass.
@Override
public List<Grade> getGradeListByClass(long classId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Grade> gradeList = new ArrayList<>();
String hql = "from Grade as G where G._class.id = :classId and G.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("classId", classId);
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());
}
}
Aggregations