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;
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations