Search in sources :

Example 11 with Activity

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

the class ActivityAdapterF method onBindViewHolder.

@Override
public void onBindViewHolder(ActivityViewHolder holder, int position) {
    Activity activity = activityList.get(position);
    holder.setView(activity, position);
}
Also used : Activity(com.remswork.project.alice.model.Activity)

Example 12 with Activity

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

the class ActivityServiceImpl method getActivityList.

@Override
public List<Activity> getActivityList() throws GradingFactorException {
    final List<Activity> activityList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Activity>, List<Activity>>() {

            @Override
            protected List<Activity> 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++) {
                            activityList.add(gson.fromJson(jsonArray.get(ctr).toString(), Activity.class));
                        }
                        return activityList;
                    } 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 : Activity");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return activityList;
                    } 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) Activity(com.remswork.project.alice.model.Activity) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with Activity

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

the class ActivityServiceImpl method getActivityListByStudentId.

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

            @Override
            protected List<Activity> 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++) {
                            activityList.add(gson.fromJson(jsonArray.get(ctr).toString(), Activity.class));
                        }
                        return activityList;
                    } 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 : Activity");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return activityList;
                    } 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) Activity(com.remswork.project.alice.model.Activity) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 14 with Activity

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

the class ActivityResource method deleteActivityById.

@DELETE
@Path("{activityId}")
public Response deleteActivityById(@PathParam("activityId") long id) {
    try {
        ActivityResourceLinks resourceLinks = new ActivityResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Activity activity = activityService.deleteActivityById(id);
        activity.addLink(resourceLinks.self(activity.getId()));
        if (activity.get_class() != null)
            activity.get_class().addLink(classResourceLinks.self(activity.get_class().getId()));
        return Response.status(Response.Status.OK).entity(activity).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 : ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) ActivityResourceLinks(com.remswork.project.alice.resource.links.ActivityResourceLinks) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Activity(com.remswork.project.alice.model.Activity)

Aggregations

Activity (com.remswork.project.alice.model.Activity)14 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)11 Message (com.remswork.project.alice.model.support.Message)7 ArrayList (java.util.ArrayList)6 AppCompatActivity (android.support.v7.app.AppCompatActivity)4 Student (com.remswork.project.alice.model.Student)4 ActivityResourceLinks (com.remswork.project.alice.resource.links.ActivityResourceLinks)4 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)4 List (java.util.List)4 AsyncTask (android.os.AsyncTask)3 CardView (android.support.v7.widget.CardView)3 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 Button (android.widget.Button)3 CompoundButton (android.widget.CompoundButton)3 TextView (android.widget.TextView)3 ToggleButton (android.widget.ToggleButton)3 Gson (com.google.gson.Gson)3 Grade (com.remswork.project.alice.model.Grade)3 IOException (java.io.IOException)3