use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class GradeDaoImpl method addGrade.
@Override
public Grade addGrade(Grade grade, long classId, long studentId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Student student = session.get(Student.class, studentId);
Term term = session.get(Term.class, termId);
if (grade == null)
throw new GradingFactorDaoException("You tried to add grade with a null value");
if (grade.getTotalScore() < 0)
throw new GradingFactorDaoException("Grade's total score is not valid");
if (grade.getActivityScore() < 0)
throw new GradingFactorDaoException("Grade's activity score is not valid");
if (grade.getAssignmentScore() < 0)
throw new GradingFactorDaoException("Grade's assignment score is not valid");
if (grade.getAttendanceScore() < 0)
throw new GradingFactorDaoException("Grade's attendance score is not valid");
if (grade.getExamScore() < 0)
throw new GradingFactorDaoException("Grade's exam score is not valid");
if (grade.getProjectScore() < 0)
throw new GradingFactorDaoException("Grade's project score is not valid");
if (grade.getQuizScore() < 0)
throw new GradingFactorDaoException("Grade's quiz score is not valid");
if (classId < 1)
throw new GradingFactorDaoException("Query param : classId is required.");
if (studentId < 1)
throw new GradingFactorDaoException("Query param : studentId is required.");
if (termId < 1)
throw new GradingFactorDaoException("Query param : termId is required.");
if (_class == null)
throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
if (student == null)
throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
if (term == null)
throw new GradingFactorDaoException("Term with id : " + termId + " doesn't exist.");
grade.set_class(_class);
grade.setStudent(student);
grade.setTerm(term);
session.persist(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.Student in project classify-system by anverliedoit.
the class StudentServiceImpl method getStudentList.
@Override
public List<Student> getStudentList() throws StudentException {
final List<Student> studentList = new ArrayList<>();
try {
return new AsyncTask<String, List<Student>, List<Student>>() {
@Override
protected List<Student> 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++) {
studentList.add(gson.fromJson(jsonArray.get(ctr).toString(), Student.class));
}
return studentList;
} 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 : Student");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return studentList;
} else
throw new StudentException("Server Error");
} catch (StudentException 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;
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class ClassServiceImpl method getStudentListOrdered.
@Deprecated
public List<Student> getStudentListOrdered(final long classId) throws ClassException {
final List<Student> studentSet = new ArrayList<>();
try {
return new AsyncTask<String, List<Student>, List<Student>>() {
@Override
protected List<Student> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(classId)).concat("/").concat("student");
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++) {
studentSet.add(gson.fromJson(jsonArray.get(ctr).toString(), Student.class));
}
Collections.sort(studentSet, new Comparator<Student>() {
@Override
public int compare(final Student object1, final Student object2) {
return object1.getLastName().compareTo(object2.getLastName());
}
});
return studentSet;
} 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);
Collections.sort(studentSet, new Comparator<Student>() {
@Override
public int compare(final Student object1, final Student object2) {
return object1.getLastName().compareTo(object2.getLastName());
}
});
return studentSet;
} 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;
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class ClassServiceImpl method getStudentList.
@Deprecated
@Override
public Set<Student> getStudentList(final long classId) throws ClassException {
final Set<Student> studentSet = new HashSet<>();
try {
return new AsyncTask<String, Set<Student>, Set<Student>>() {
@Override
protected Set<Student> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(classId)).concat("/").concat("student");
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++) {
studentSet.add(gson.fromJson(jsonArray.get(ctr).toString(), Student.class));
}
return studentSet;
} 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 studentSet;
} 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;
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class ExamInputActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_z_input_exam);
init();
buttonSubmit.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
final long classId = getIntent().getExtras().getLong("classId");
try {
Exam exam = new Exam();
exam.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Exam");
exam.setDate(textViewDate.getText().toString());
if (editTextTotal.getText().toString().equals("")) {
toggleButtonhideandshow.setChecked(false);
getDialogEmptyTotal.setVisibility(View.VISIBLE);
recyclerViewStudentInput.setVisibility(View.GONE);
return;
} else {
exam.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
}
studentAdapter.setTotalItem(exam.getItemTotal());
studentAdapter.onValidate(true);
if (studentAdapter.isNoError()) {
exam = examService.addExam(exam, 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);
examService.addExamResult(score, exam.getId(), student.getId());
// Adding Grade for exam
new Thread(new Runnable() {
@Override
public void run() {
try {
final List<Exam> examList = examService.getExamListByClassId(classId);
final double[] fExam = new double[examList.size()];
final long sId = studentId;
double tempTotal = 0;
try {
List<Grade> tempList = gradeService.getGradeListByClass(classId, sId, 1L);
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, 1L);
}
final Grade lGrade = grade;
final long gradeId = grade.getId();
for (int i = 0; i < fExam.length; i++) {
final double total = examList.get(i).getItemTotal();
final double score = examService.getExamResultByExamAndStudentId(examList.get(i).getId(), sId).getScore();
fExam[i] = (score / total) * 100;
Log.i("Exam[" + i + "] :", fExam[i] + "");
}
for (int i = 0; i < fExam.length; i++) tempTotal += fExam[i];
// after looping
if (fExam.length > 0)
tempTotal /= fExam.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(ExamInputActivity.this, "Success", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ExamInputActivity.this, "Failed", Toast.LENGTH_LONG).show();
dialogFailed.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Aggregations