Search in sources :

Example 1 with Assignment

use of com.remswork.project.alice.model.Assignment in project classify-system by anverliedoit.

the class AssignmentResource method getAssignmentById.

@GET
@Path("{assignmentId}")
public Response getAssignmentById(@PathParam("assignmentId") long id) {
    try {
        AssignmentResourceLinks resourceLinks = new AssignmentResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Assignment assignment = assignmentService.getAssignmentById(id);
        assignment.addLink(resourceLinks.self(id));
        if (assignment.get_class() != null)
            assignment.get_class().addLink(classResourceLinks.self(assignment.get_class().getId()));
        return Response.status(Response.Status.OK).entity(assignment).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 : Assignment(com.remswork.project.alice.model.Assignment) ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) AssignmentResourceLinks(com.remswork.project.alice.resource.links.AssignmentResourceLinks)

Example 2 with Assignment

use of com.remswork.project.alice.model.Assignment in project classify-system by anverliedoit.

the class AssignmentServiceImpl method getAssignmentListByClassId.

@Override
public List<Assignment> getAssignmentListByClassId(final long classId) throws GradingFactorException {
    final List<Assignment> assignmentList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Assignment>, List<Assignment>>() {

            @Override
            protected List<Assignment> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?classId=").concat(String.valueOf(classId));
                    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++) {
                            assignmentList.add(gson.fromJson(jsonArray.get(ctr).toString(), Assignment.class));
                        }
                        return assignmentList;
                    } 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 : Assignment");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return assignmentList;
                    } 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) IOException(java.io.IOException) URL(java.net.URL) Assignment(com.remswork.project.alice.model.Assignment) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with Assignment

use of com.remswork.project.alice.model.Assignment in project classify-system by anverliedoit.

the class AssignmentServiceImpl method getAssignmentListByStudentId.

@Override
public List<Assignment> getAssignmentListByStudentId(final long studentId, final long termId) throws GradingFactorException {
    final List<Assignment> assignmentList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Assignment>, List<Assignment>>() {

            @Override
            protected List<Assignment> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).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++) {
                            assignmentList.add(gson.fromJson(jsonArray.get(ctr).toString(), Assignment.class));
                        }
                        return assignmentList;
                    } 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 : Assignment");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return assignmentList;
                    } 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) IOException(java.io.IOException) URL(java.net.URL) Assignment(com.remswork.project.alice.model.Assignment) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with Assignment

use of com.remswork.project.alice.model.Assignment in project classify-system by anverliedoit.

the class AssignmentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(AssignmentViewHolder holder, int position) {
    Assignment assignment = assignmentList.get(position);
    holder.setView(assignment, position);
}
Also used : Assignment(com.remswork.project.alice.model.Assignment)

Example 5 with Assignment

use of com.remswork.project.alice.model.Assignment in project classify-system by anverliedoit.

the class AssignmentAdapterF method onBindViewHolder.

@Override
public void onBindViewHolder(AssignmentViewHolder holder, int position) {
    Assignment assignment = assignmentList.get(position);
    holder.setView(assignment, position);
}
Also used : Assignment(com.remswork.project.alice.model.Assignment)

Aggregations

Assignment (com.remswork.project.alice.model.Assignment)12 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)10 Message (com.remswork.project.alice.model.support.Message)7 ArrayList (java.util.ArrayList)5 AssignmentResourceLinks (com.remswork.project.alice.resource.links.AssignmentResourceLinks)4 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)4 AsyncTask (android.os.AsyncTask)3 Gson (com.google.gson.Gson)3 Student (com.remswork.project.alice.model.Student)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 List (java.util.List)3 ExecutionException (java.util.concurrent.ExecutionException)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 CardView (android.support.v7.widget.CardView)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2