Search in sources :

Example 21 with Formula

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

the class FormulaServiceImpl method getFormulaListByTeacherId.

@Override
public List<Formula> getFormulaListByTeacherId(final long teacherId) throws GradingFactorException {
    final List<Formula> formulaList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Formula>, List<Formula>>() {

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

Example 22 with Formula

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

the class FormulaResource method updateFormulaById.

@PUT
@Path("{formulaId}")
public Response updateFormulaById(@PathParam("formulaId") long id, Formula newFormula) {
    try {
        FormulaResourceLinks resourceLinks = new FormulaResourceLinks(uriInfo);
        SubjectResourceLinks subjectResourceLinks = new SubjectResourceLinks(uriInfo);
        TeacherResourceLinks teacherResourceLinks = new TeacherResourceLinks(uriInfo);
        Formula formula = formulaService.updateFormulaById(id, newFormula, subjectId, teacherId, termId);
        formula.addLink(resourceLinks.self(formula.getId()));
        if (formula.getTeacher() != null)
            formula.getTeacher().addLink(teacherResourceLinks.self(formula.getTeacher().getId()));
        if (formula.getSubject() != null)
            formula.getSubject().addLink(subjectResourceLinks.self(formula.getSubject().getId()));
        return Response.status(Response.Status.OK).entity(formula).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 : Formula(com.remswork.project.alice.model.Formula) SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) FormulaResourceLinks(com.remswork.project.alice.resource.links.FormulaResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks)

Example 23 with Formula

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

the class FormulaResource method deleteFormulaById.

@DELETE
@Path("{formulaId}")
public Response deleteFormulaById(@PathParam("formulaId") long id) {
    try {
        FormulaResourceLinks resourceLinks = new FormulaResourceLinks(uriInfo);
        SubjectResourceLinks subjectResourceLinks = new SubjectResourceLinks(uriInfo);
        TeacherResourceLinks teacherResourceLinks = new TeacherResourceLinks(uriInfo);
        Formula formula = formulaService.deleteFormulaById(id);
        formula.addLink(resourceLinks.self(formula.getId()));
        if (formula.getTeacher() != null)
            formula.getTeacher().addLink(teacherResourceLinks.self(formula.getTeacher().getId()));
        if (formula.getSubject() != null)
            formula.getSubject().addLink(subjectResourceLinks.self(formula.getSubject().getId()));
        return Response.status(Response.Status.OK).entity(formula).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 : Formula(com.remswork.project.alice.model.Formula) SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) FormulaResourceLinks(com.remswork.project.alice.resource.links.FormulaResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks)

Example 24 with Formula

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

the class FormulaResource method getFormula.

@GET
@Path("0")
public Response getFormula() {
    try {
        FormulaResourceLinks resourceLinks = new FormulaResourceLinks(uriInfo);
        SubjectResourceLinks subjectResourceLinks = new SubjectResourceLinks(uriInfo);
        TeacherResourceLinks teacherResourceLinks = new TeacherResourceLinks(uriInfo);
        Formula formula = formulaService.getFormulaBySubjectAndTeacherId(subjectId, teacherId, termId);
        formula.addLink(resourceLinks.self(formula.getId()));
        if (formula.getSubject() != null)
            formula.getSubject().addLink(subjectResourceLinks.self(formula.getSubject().getId()));
        if (formula.getTeacher() != null)
            formula.getTeacher().addLink(teacherResourceLinks.self(formula.getTeacher().getId()));
        return Response.status(Response.Status.OK).entity(formula).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 : Formula(com.remswork.project.alice.model.Formula) SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) FormulaResourceLinks(com.remswork.project.alice.resource.links.FormulaResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks)

Example 25 with Formula

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

the class FormulaResource method getFormulaList.

@GET
public Response getFormulaList() {
    try {
        List<Formula> formulaList;
        FormulaResourceLinks resourceLinks = new FormulaResourceLinks(uriInfo);
        SubjectResourceLinks subjectResourceLinks = new SubjectResourceLinks(uriInfo);
        TeacherResourceLinks teacherResourceLinks = new TeacherResourceLinks(uriInfo);
        if (teacherId != 0)
            formulaList = formulaService.getFormulaListByTeacherId(teacherId);
        else
            formulaList = formulaService.getFormulaList();
        for (Formula formula : formulaList) {
            formula.addLink(resourceLinks.self(formula.getId()));
            if (formula.getTeacher() != null)
                formula.getTeacher().addLink(teacherResourceLinks.self(formula.getTeacher().getId()));
            if (formula.getSubject() != null)
                formula.getSubject().addLink(subjectResourceLinks.self(formula.getSubject().getId()));
        }
        GenericEntity<List<Formula>> entity = new GenericEntity<List<Formula>>(formulaList) {
        };
        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 : Formula(com.remswork.project.alice.model.Formula) SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) FormulaResourceLinks(com.remswork.project.alice.resource.links.FormulaResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks) List(java.util.List)

Aggregations

Formula (com.remswork.project.alice.model.Formula)25 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)19 FormulaServiceImpl (com.remswork.project.alice.service.impl.FormulaServiceImpl)10 Message (com.remswork.project.alice.model.support.Message)7 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)6 Class (com.remswork.project.alice.model.Class)6 Grade (com.remswork.project.alice.model.Grade)6 Student (com.remswork.project.alice.model.Student)6 FormulaService (com.remswork.project.alice.service.FormulaService)6 GradeService (com.remswork.project.alice.service.GradeService)6 GradeServiceImpl (com.remswork.project.alice.service.impl.GradeServiceImpl)6 FormulaResourceLinks (com.remswork.project.alice.resource.links.FormulaResourceLinks)5 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)5 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)5 ArrayList (java.util.ArrayList)5 Session (org.hibernate.Session)5 View (android.view.View)4 TextView (android.widget.TextView)4 CompoundButton (android.widget.CompoundButton)3 Subject (com.remswork.project.alice.model.Subject)3