use of com.remswork.project.alice.model.Term in project classify-system by anverliedoit.
the class TermResource method getTermList.
@GET
public Response getTermList() {
try {
TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
List<Term> termList = termService.getTermList();
for (Term term : termList) term.addLink(resourceLinks.self(term.getId()));
GenericEntity<List<Term>> entity = new GenericEntity<List<Term>>(termList) {
};
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();
}
}
use of com.remswork.project.alice.model.Term in project classify-system by anverliedoit.
the class TermResource method updateTermById.
@PUT
@Path("{termId}")
public Response updateTermById(@PathParam("termId") long id, Term newTerm) {
try {
TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
Term term = termService.updateTermById(id, newTerm);
term.addLink(resourceLinks.self(id));
return Response.status(Response.Status.OK).entity(term).build();
} catch (GradingFactorException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.model.Term 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.Term in project classify-system by anverliedoit.
the class TermServiceImpl method getTermList.
@Override
public List<Term> getTermList() throws GradingFactorException {
final List<Term> termList = new ArrayList<>();
try {
return new AsyncTask<String, List<Term>, List<Term>>() {
@Override
protected List<Term> 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++) {
termList.add(gson.fromJson(jsonArray.get(ctr).toString(), Term.class));
}
return termList;
} 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 : Term");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return termList;
} 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.Term in project classify-system by anverliedoit.
the class TermResource method deleteTermById.
@DELETE
@Path("{termId}")
public Response deleteTermById(@PathParam("termId") long id) {
try {
TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
Term term = termService.deleteTermById(id);
term.addLink(resourceLinks.self(id));
return Response.status(Response.Status.OK).entity(term).build();
} catch (GradingFactorException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
Aggregations