Search in sources :

Example 1 with Subject

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

the class SubjectResource method deleteSubjectById.

@DELETE
@Path("{subjectId}")
public Response deleteSubjectById(@PathParam("subjectId") long id) {
    try {
        SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
        Subject subject = subjectService.deleteSubjectById(id);
        subject.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(subject).build();
    } catch (SubjectException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject)

Example 2 with Subject

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

the class SubjectResource method getSubject.

@GET
@Path("0")
public Response getSubject(@QueryParam("classId") long classId, @QueryParam("scheduleId") long scheduleId, @QueryParam("teacherId") long teacherId) {
    try {
        if (classId != 0 && teacherId != 0) {
            SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
            Subject subject = subjectService.getSubjectByClassAndTeacherId(classId, teacherId);
            subject.addLink(resourceLinks.self(subject.getId()));
            return Response.status(Response.Status.OK).entity(subject).build();
        } else if (scheduleId != 0) {
            SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
            Subject subject = subjectService.getSubjectByScheduleId(scheduleId);
            subject.addLink(resourceLinks.self(subject.getId()));
            return Response.status(Response.Status.OK).entity(subject).build();
        } else
            throw new SubjectException("No subject found");
    } catch (SubjectException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject)

Example 3 with Subject

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

the class SubjectResource method getSubjectListByTeacherIdUnique.

@GET
@Path("1/unique")
@Deprecated
public Response getSubjectListByTeacherIdUnique(@QueryParam("teacherId") long teacherId) {
    try {
        SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
        List<Subject> subjectList = subjectService.getSubjectListByTeacherIdUnique(teacherId);
        for (Subject subject : subjectList) subject.addLink(resourceLinks.self(subject.getId()));
        GenericEntity<List<Subject>> entity = new GenericEntity<List<Subject>>(subjectList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (SubjectException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) List(java.util.List) Subject(com.remswork.project.alice.model.Subject)

Example 4 with Subject

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

the class SubjectServiceImpl method getSubjectList.

@Override
public List<Subject> getSubjectList() throws SubjectException {
    final List<Subject> subjectList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Subject>, List<Subject>>() {

            @Override
            protected List<Subject> 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++) {
                            subjectList.add(gson.fromJson(jsonArray.get(ctr).toString(), Subject.class));
                        }
                        return subjectList;
                    } 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 : Subject");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return subjectList;
                    } else
                        throw new SubjectException("Server Error");
                } catch (SubjectException 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) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) SubjectException(com.remswork.project.alice.exception.SubjectException) JSONException(org.json.JSONException) IOException(java.io.IOException) Subject(com.remswork.project.alice.model.Subject) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Subject

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

the class SubjectServiceImpl method getSubjectListByStudentId.

@Override
public List<Subject> getSubjectListByStudentId(final long studentId) throws SubjectException {
    final List<Subject> subjectList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Subject>, List<Subject>>() {

            @Override
            protected List<Subject> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat("1").concat("?studentId=").concat(String.valueOf(studentId));
                    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++) {
                            subjectList.add(gson.fromJson(jsonArray.get(ctr).toString(), Subject.class));
                        }
                        return subjectList;
                    } 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 : Subject");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return subjectList;
                    } else
                        throw new SubjectException("Server Error");
                } catch (SubjectException 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) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) SubjectException(com.remswork.project.alice.exception.SubjectException) JSONException(org.json.JSONException) IOException(java.io.IOException) Subject(com.remswork.project.alice.model.Subject) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Subject (com.remswork.project.alice.model.Subject)29 SubjectException (com.remswork.project.alice.exception.SubjectException)23 Message (com.remswork.project.alice.model.support.Message)20 SubjectServiceException (com.remswork.project.alice.web.service.exception.SubjectServiceException)9 Client (javax.ws.rs.client.Client)9 WebTarget (javax.ws.rs.client.WebTarget)9 Response (javax.ws.rs.core.Response)9 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)7 List (java.util.List)6 Teacher (com.remswork.project.alice.model.Teacher)5 ArrayList (java.util.ArrayList)5 AsyncTask (android.os.AsyncTask)4 Gson (com.google.gson.Gson)4 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ExecutionException (java.util.concurrent.ExecutionException)4 JSONArray (org.json.JSONArray)4