use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.
the class GradeDaoImpl method getGradeListByStudentId.
@Override
public List<Grade> getGradeListByStudentId(long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Grade> gradeList = new ArrayList<>();
String hql = "from Grade as G where G.student.id = :studentId";
Query query = session.createQuery(hql);
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());
}
}
use of com.remswork.project.alice.model.Grade in project classify-system by anverliedoit.
the class GradeDaoImpl method getGradeById.
@Override
public Grade getGradeById(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.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 GradeServiceImpl method getGradeListByClass.
@Override
public List<Grade> getGradeListByClass(final long classId, final long studentId, final long termId) throws GradingFactorException {
final List<Grade> gradeList = new ArrayList<>();
try {
return new AsyncTask<String, List<Grade>, List<Grade>>() {
@Override
protected List<Grade> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?classId=").concat(String.valueOf(classId)).concat("&studentId=").concat(String.valueOf(studentId)).concat("&termId=").concat(String.valueOf(termId));
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++) {
gradeList.add(gson.fromJson(jsonArray.get(ctr).toString(), Grade.class));
}
return gradeList;
} 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 : Grade");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return gradeList;
} else
throw new GradingFactorException("Server Error");
} catch (GradingFactorException 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.Grade in project classify-system by anverliedoit.
the class GradeServiceImpl method getGradeListByStudentId.
@Override
public List<Grade> getGradeListByStudentId(final long studenId) throws GradingFactorException {
final List<Grade> gradeList = new ArrayList<>();
try {
return new AsyncTask<String, List<Grade>, List<Grade>>() {
@Override
protected List<Grade> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?studentId=").concat(String.valueOf(studenId));
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++) {
gradeList.add(gson.fromJson(jsonArray.get(ctr).toString(), Grade.class));
}
return gradeList;
} 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 : Grade");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return gradeList;
} else
throw new GradingFactorException("Server Error");
} catch (GradingFactorException 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.Grade in project classify-system by anverliedoit.
the class GradeResource method getGradeList.
@GET
public Response getGradeList() {
try {
List<Grade> gradeList;
if (classId != 0 && studentId != 0 && termId != 0)
gradeList = gradeService.getGradeListByClass(classId, studentId, termId);
else if (classId != 0 && studentId != 0)
gradeList = gradeService.getGradeListByClass(classId, studentId);
else if (studentId != 0 && termId != 0)
gradeList = gradeService.getGradeListByStudentId(studentId, termId);
else if (studentId != 0)
gradeList = gradeService.getGradeListByStudentId(studentId);
else
gradeList = gradeService.getGradeList();
GenericEntity<List<Grade>> entity = new GenericEntity<List<Grade>>(gradeList) {
};
return Response.status(Response.Status.OK).entity(entity).build();
} catch (GradingFactorException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
Aggregations