Search in sources :

Example 1 with Term

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();
    }
}
Also used : TermResourceLinks(com.remswork.project.alice.resource.links.TermResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) List(java.util.List) Term(com.remswork.project.alice.model.Term)

Example 2 with Term

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();
    }
}
Also used : TermResourceLinks(com.remswork.project.alice.resource.links.TermResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Term(com.remswork.project.alice.model.Term)

Example 3 with Term

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());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Class(com.remswork.project.alice.model.Class) Term(com.remswork.project.alice.model.Term) Student(com.remswork.project.alice.model.Student) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 4 with Term

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;
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) Term(com.remswork.project.alice.model.Term) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Term

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();
    }
}
Also used : TermResourceLinks(com.remswork.project.alice.resource.links.TermResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Term(com.remswork.project.alice.model.Term)

Aggregations

GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)7 Term (com.remswork.project.alice.model.Term)7 Message (com.remswork.project.alice.model.support.Message)5 TermResourceLinks (com.remswork.project.alice.resource.links.TermResourceLinks)4 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)2 Session (org.hibernate.Session)2 AsyncTask (android.os.AsyncTask)1 Gson (com.google.gson.Gson)1 Class (com.remswork.project.alice.model.Class)1 Formula (com.remswork.project.alice.model.Formula)1 Student (com.remswork.project.alice.model.Student)1 Subject (com.remswork.project.alice.model.Subject)1 Teacher (com.remswork.project.alice.model.Teacher)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1